<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Source: ServerLayer.js</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Source: ServerLayer.js</h1>

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>/*
 * @Description: In User Settings Edit
 * @Author: xiaoying
 * @Date: 2019-09-10 10:46:01
 * @LastEditTime: 2019-09-21 13:53:36
 * @LastEditors: mayuanye
 */
import { NativeModules } from 'react-native';
import GroupLayer from './GroupLayer';
import VectorMapServer from './VectorMapServer.js';
import VectorTileMapServer from './VectorTileMapServer.js';
import OGCWMTSMapServer from './OGCWMTSMapServer.js';
import TileMapServer from './TileMapServer.js';
let SL = NativeModules.JSServerLayer;

/**
 * @class ServerLayer
 * @description 服务图层
 */
export default class ServerLayer extends GroupLayer {
  constructor() {
    super();
    Object.defineProperty(this, '_MGServerLayerId', {
      get: function() {
        return this._MGGroupLayerId;
      },
      set: function(_MGServerLayerId) {
        this._MGGroupLayerId = _MGServerLayerId;
      },
    });
  }

  /**
   * 构造一个新的ServerLayer对象
   *
   * @memberof ServerLayer
   * @returns {Promise&lt;ServerLayer>}
   */
  async createObj() {
    try {
      var { ServerLayerId } = await SL.createObj();
      var serverLayer = new ServerLayer();
      serverLayer._MGServerLayerId = ServerLayerId;
      return serverLayer;
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 设置地图服务
   *
   * @memberof ServerLayer
   * @param {Object} mapServer 地图服务对象 （MapServer类型的Object）
   * @returns {Promise&lt;Void>}
   */
  async setMapServer(mapServer) {
    try {
      await SL.setMapServer(this._MGServerLayerId, mapServer._MGMapServerId);
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 设置服务图层的数据读取模式
   *
   * @memberof ServerLayer
   * @param {Number} accessMode 地图服务访问模式（int类型的Number），例：1--MapServerAccessMode.ServerAndCache
   * @returns {Promise&lt;void>}
   */
  async setAccessMode(accessMode) {
    try {
      await SL.setAccessMode(this._MGServerLayerId, accessMode);
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 获取地图服务
   *
   * @memberof ServerLayer
   * @returns {Promise&lt;MapServer>}
   */
  async getMapServer() {
    try {
      var { MapServerId, MapBrowseType, Type } = await SL.getMapServer(
        this._MGServerLayerId
      );
      let mapServer = ServerLayer.createMapServerByIdAndType(
        MapServerId,
        MapBrowseType,
        Type
      );
      return mapServer;
    } catch (e) {
      console.error(e);
    }
  }

  // 通过地图服务类型、地图浏览类型创建MapServer对象
  static async createMapServerByIdAndType(mapServerId, mapBrowseType, type) {
    let mapServer = null;
    if (mapServerId != null) {
      if (mapBrowseType === 1) {
        // 地图浏览类型 -- 矢量
        mapServer = new VectorMapServer();
        mapServer._MGMapServerId = mapServerId;
      } else if (mapBrowseType === 2) {
        // 地图浏览类型 -- 矢量瓦片
        mapServer = new VectorTileMapServer();
        mapServer._MGMapServerId = mapServerId;
      } else {
        // 地图浏览类型 -- 任意
        if (type != null) {
          if (type === 'OGCWMTS') {
            // 服务类型 -- OGCWMTS地图服务
            mapServer = new OGCWMTSMapServer();
            mapServer._MGMapServerId = mapServerId;
          } else {
            mapServer = new TileMapServer();
            mapServer._MGMapServerId = mapServerId;
          }
        }
      }
    }

    return mapServer;
  }
  /**
   * 获取服务图层的数据读取模式
   *
   * @memberof ServerLayer
   * @returns {Number} 地图服务访问模式（int类型的Number），例：1--MapServerAccessMode.ServerAndCache
   */
  async getAccessMode() {
    try {
      let accessMode = await SL.getAccessMode(this._MGServerLayerId);
      return accessMode;
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 设置服务URL
   *
   * @memberof ServerLayer
   * @param {String} strURL 服务URL
   * @returns {boolean} 成功返回true
   */
  async setURL(strURL) {
    try {
      let result = await SL.setURL(this._MGServerLayerId, strURL);
      return result;
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 根据类型创建地图服务
   *
   * @memberof ServerLayer
   * @param {String} type MapServer中的类型常量，如：MapServer.MapServerType.MAPSERVER_TYPE_OGC_WMS
   * @returns {Promise&lt;MapServer>} 返回创建好的MapServer对象
   */
  static async createMapServer(type) {
    try {
      var { MapServerId, MapServerBrowseType, Type } = await SL.createMapServer(
        type
      );
      let mapServer = null;
      if (MapServerId !== '' &amp;&amp; MapServerBrowseType !== -1) {
        if (MapServerBrowseType === 1) {
          mapServer = new VectorMapServer();
          mapServer._MGMapServerId = MapServerId;
        } else if (MapServerBrowseType === 2) {
          mapServer = new VectorTileMapServer();
          mapServer._MGMapServerId = MapServerId;
        } else {
          if (Type === 'OGCWMTS') {
            mapServer = new OGCWMTSMapServer();
            mapServer._MGMapServerId = MapServerId;
          } else {
            mapServer = new TileMapServer();
            mapServer._MGMapServerId = MapServerId;
          }
        }
      }
      return mapServer;
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 清除缓存(内存缓存+本地文件缓存)
   *
   * @memberof ServerLayer
   * @returns {Promise&lt;Void>}
   */
  async clearCache() {
    try {
      await SL.clearCache(this._MGServerLayerId);
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 设置是否开启自适应显示
   *
   * @memberof ServerLayer
   * @param {boolean} flag true为开启,false不开启。默认情况下不开启。
   * @returns {Promise&lt;Void>}
   */
  async setAutoScaleFlag(flag) {
    try {
      await SL.setAutoScaleFlag(this._MGServerLayerId, flag);
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 获取是否开启自适应显示。
   *
   * @memberof ServerLayer
   * @returns {boolean}  true为开启,false不开启。默认情况下不开启。
   */
  async getAutoScaleFlag() {
    try {
      let result = await SL.getAutoScaleFlag(this._MGServerLayerId);
      return result;
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 设置缓存路径
   *
   * @memberof ServerLayer
   * @param {String} strCacheLocation 缓存路径.用户需要保证该目录存在，否则设置失败。
   * @returns {Number}  0:失败.1:成功（int类型的Number）
   */
  async setCacheLocation(strCacheLocation) {
    try {
      let result = await SL.setCacheLocation(
        this._MGServerLayerId,
        strCacheLocation
      );
      return result;
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 获取缓存路径。
   *
   * @memberof ServerLayer
   * @returns {String}  缓存路径
   */
  async getCacheLocation() {
    try {
      let result = await SL.getCacheLocation(this._MGServerLayerId);
      return result;
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 预缓存(可根据级别或者范围进行缓存)
   * 该方法为异步方法，用户可以通过ServerLayer上的TilePreFetchListener获取预缓存的任务状态
   *
   * @memberof ServerLayer
   * @param {Number} lMinZoom 预缓存的最小级别
   * @param {Number} lMaxZoom 预缓存的最小级别
   * @param {Object} rect 预缓存的空间范围  （Rect类型的Object）
   * @memberof ServerLayer
   * @returns {Number} （int类型的Number） >=0成功,返回任务ID,-1:没有设置MapServer,-2:MapServer类型不支持预缓存,-3:参数不合法.
   * 任务ID,从0开始，用户可以通过该返回值区分不同的预缓存任务.
   */
  async preFetch(lMinZoom, lMaxZoom, rect) {
    try {
      let result = await SL.preFetch(
        this._MGServerLayerId,
        lMinZoom,
        lMaxZoom,
        rect._MGRectId
      );
      return result;
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 停止预缓存
   *
   * @memberof ServerLayer
   * @param {Number} taskId 任务Id (int类型的Number)
   * @returns {Number} >0成功 （int类型的Number）
   */
  async stopFetch(taskId) {
    try {
      let result = await SL.stopFetch(this._MGServerLayerId, taskId);
      return result;
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 设置预缓存状态监听类
   *
   * @memberof ServerLayer
   * @returns {Number} 1 ：成功，0：失败。
   */
  async registerTilePreFetchListener() {
    try {
      let result = await SL.registerTilePreFetchListener(this._MGServerLayerId);
      return result;
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 移除预缓存状态监听类
   *
   * @memberof ServerLayer
   * @returns {Object} 预缓存状态监听对象。
   */
  async removeTilePreFetchListener() {
    try {
      await SL.removeTilePreFetchListener(this._MGServerLayerId);
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 设置透明度,0-100 默认为0,表示不透明
   *
   * @memberof ServerLayer
   * @param {Number} trans 透明度，0-100的整数
   * @returns {Number} 1：成功，0：失败。(int类型的Number)
   */
  async setTransparency(trans) {
    try {
      let result = await SL.setTransparency(this._MGServerLayerId, trans);
      return result;
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 获取透明度
   *
   * @memberof ServerLayer
   * @returns {Number} 透明度,0-100的整数。 默认为0,表示不透明
   */
  async getTransparency() {
    try {
      let result = await SL.getTransparency(this._MGServerLayerId);
      return result;
    } catch (e) {
      console.error(e);
    }
  }
}
</code></pre>
        </article>
    </section>




</div>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AnnClsInfo.html">AnnClsInfo</a></li><li><a href="AnnInfo.html">AnnInfo</a></li><li><a href="Annotation.html">Annotation</a></li><li><a href="AnnotationCls.html">AnnotationCls</a></li><li><a href="AnnotationsOverlay.html">AnnotationsOverlay</a></li><li><a href="AnnotationView.html">AnnotationView</a></li><li><a href="BasCls.html">BasCls</a></li><li><a href="ClassItemValue.html">ClassItemValue</a></li><li><a href="CoordinateConvert.html">CoordinateConvert</a></li><li><a href="CoordinateConvertParameter.html">CoordinateConvertParameter</a></li><li><a href="CrossData.html">CrossData</a></li><li><a href="DataBase.html">DataBase</a></li><li><a href="DataBaseSync.html">DataBaseSync</a></li><li><a href="Document.html">Document</a></li><li><a href="DocumentItem.html">DocumentItem</a></li><li><a href="Dot.html">Dot</a></li><li><a href="Dot3D.html">Dot3D</a></li><li><a href="Dots.html">Dots</a></li><li><a href="Dots3D.html">Dots3D</a></li><li><a href="DownloadDataBaseParmeters.html">DownloadDataBaseParmeters</a></li><li><a href="DownloadLayerOption.html">DownloadLayerOption</a></li><li><a href="ElpParam.html">ElpParam</a></li><li><a href="ElpTransformation.html">ElpTransformation</a></li><li><a href="ElpTransParam.html">ElpTransParam</a></li><li><a href="Environment.html">Environment</a></li><li><a href="ExtField.html">ExtField</a></li><li><a href="FClsInfo.html">FClsInfo</a></li><li><a href="Feature.html">Feature</a></li><li><a href="FeatureEdit.html">FeatureEdit</a></li><li><a href="FeaturePagedResult.html">FeaturePagedResult</a></li><li><a href="FeatureQuery.html">FeatureQuery</a></li><li><a href="FeatureSync.html">FeatureSync</a></li><li><a href="Field.html">Field</a></li><li><a href="Fields.html">Fields</a></li><li><a href="FillStyle.html">FillStyle</a></li><li><a href="GeneralVectorLabel.html">GeneralVectorLabel</a></li><li><a href="GeoAnno.html">GeoAnno</a></li><li><a href="GeoLine.html">GeoLine</a></li><li><a href="GeoLines.html">GeoLines</a></li><li><a href="Geometry.html">Geometry</a></li><li><a href="GeometryExp.html">GeometryExp</a></li><li><a href="GeometryParams.html">GeometryParams</a></li><li><a href="GeomInfo.html">GeomInfo</a></li><li><a href="GeoPoints.html">GeoPoints</a></li><li><a href="GeoPolygon.html">GeoPolygon</a></li><li><a href="GeoPolygons.html">GeoPolygons</a></li><li><a href="GeoVarLine.html">GeoVarLine</a></li><li><a href="Graphic.html">Graphic</a></li><li><a href="GraphicCircle.html">GraphicCircle</a></li><li><a href="GraphicHeatmap.html">GraphicHeatmap</a></li><li><a href="GraphicImage.html">GraphicImage</a></li><li><a href="GraphicMultiPoint.html">GraphicMultiPoint</a></li><li><a href="GraphicPoint.html">GraphicPoint</a></li><li><a href="GraphicPolygon.html">GraphicPolygon</a></li><li><a href="GraphicPolylin.html">GraphicPolylin</a></li><li><a href="GraphicsOverlay.html">GraphicsOverlay</a></li><li><a href="GraphicsOverlays.html">GraphicsOverlays</a></li><li><a href="GraphicStippleLine.html">GraphicStippleLine</a></li><li><a href="GraphicText.html">GraphicText</a></li><li><a href="GroupLayer.html">GroupLayer</a></li><li><a href="HeatmapPoint.html">HeatmapPoint</a></li><li><a href="Image.html">Image</a></li><li><a href="IntUser.html">IntUser</a></li><li><a href="Label.html">Label</a></li><li><a href="LabelInfo.html">LabelInfo</a></li><li><a href="LatLng.html">LatLng</a></li><li><a href="LayerEnum.html">LayerEnum</a></li><li><a href="LinePlaceInfo.html">LinePlaceInfo</a></li><li><a href="LineStyle.html">LineStyle</a></li><li><a href="LinInfo.html">LinInfo</a></li><li><a href="MagnifierOption.html">MagnifierOption</a></li><li><a href="Map.html">Map</a></li><li><a href="MapLayer.html">MapLayer</a></li><li><a href="MapPosition.html">MapPosition</a></li><li><a href="Maps.html">Maps</a></li><li><a href="MapServer.html">MapServer</a></li><li><a href="MapServiceInfo.html">MapServiceInfo</a></li><li><a href="MapServiceLayerInfo.html">MapServiceLayerInfo</a></li><li><a href="MapView.html">MapView</a></li><li><a href="MeasureContentWillChangeListener.html">MeasureContentWillChangeListener</a></li><li><a href="MeasureOption.html">MeasureOption</a></li><li><a href="Model.html">Model</a></li><li><a href="ModelsOverlay.html">ModelsOverlay</a></li><li><a href="MultiClassTheme.html">MultiClassTheme</a></li><li><a href="MultiClassThemeInfo.html">MultiClassThemeInfo</a></li><li><a href="OGCWMTSMapServer.html">OGCWMTSMapServer</a></li><li><a href="PntInfo.html">PntInfo</a></li><li><a href="PointF.html">PointF</a></li><li><a href="PointPlaceInfo.html">PointPlaceInfo</a></li><li><a href="PointStyle.html">PointStyle</a></li><li><a href="QueryBound.html">QueryBound</a></li><li><a href="QueryDef.html">QueryDef</a></li><li><a href="RangeTheme.html">RangeTheme</a></li><li><a href="RangeThemeInfo.html">RangeThemeInfo</a></li><li><a href="Record.html">Record</a></li><li><a href="RecordSet.html">RecordSet</a></li><li><a href="Rect.html">Rect</a></li><li><a href="RegInfo.html">RegInfo</a></li><li><a href="RegionPlaceInfo.html">RegionPlaceInfo</a></li><li><a href="ServerLayer.html">ServerLayer</a></li><li><a href="SFeatureCls.html">SFeatureCls</a></li><li><a href="SimpleLabel.html">SimpleLabel</a></li><li><a href="SimpleModelLayer.html">SimpleModelLayer</a></li><li><a href="SimpleModelLayerUtil.html">SimpleModelLayerUtil</a></li><li><a href="SimpleTheme.html">SimpleTheme</a></li><li><a href="SketchEditor.html">SketchEditor</a></li><li><a href="SketchStyle.html">SketchStyle</a></li><li><a href="SnappingOption.html">SnappingOption</a></li><li><a href="SpaAnalysis.html">SpaAnalysis</a></li><li><a href="SpaCalculator.html">SpaCalculator</a></li><li><a href="SpaProjection.html">SpaProjection</a></li><li><a href="SpaRelation.html">SpaRelation</a></li><li><a href="SRefData.html">SRefData</a></li><li><a href="SyncBase.html">SyncBase</a></li><li><a href="SyncDataBaseParmeters.html">SyncDataBaseParmeters</a></li><li><a href="SyncLayerOption.html">SyncLayerOption</a></li><li><a href="TextAnnInfo.html">TextAnnInfo</a></li><li><a href="TextAnno.html">TextAnno</a></li><li><a href="TextStyle.html">TextStyle</a></li><li><a href="Theme.html">Theme</a></li><li><a href="ThemeInfo.html">ThemeInfo</a></li><li><a href="Themes.html">Themes</a></li><li><a href="TileMapServer.html">TileMapServer</a></li><li><a href="UniqueTheme.html">UniqueTheme</a></li><li><a href="UniqueThemeInfo.html">UniqueThemeInfo</a></li><li><a href="VectorCls.html">VectorCls</a></li><li><a href="VectorLabel.html">VectorLabel</a></li><li><a href="VectorLayer.html">VectorLayer</a></li><li><a href="VectorMapServer.html">VectorMapServer</a></li><li><a href="VectorTheme.html">VectorTheme</a></li><li><a href="VectorTileMapServer.html">VectorTileMapServer</a></li><li><a href="VisualMap.html">VisualMap</a></li><li><a href="XClsInfo.html">XClsInfo</a></li></ul><h3>Global</h3><ul><li><a href="global.html#addAnnotation">addAnnotation</a></li><li><a href="global.html#addAnnotations">addAnnotations</a></li><li><a href="global.html#animatePosition">animatePosition</a></li><li><a href="global.html#distanceOfGeometry">distanceOfGeometry</a></li><li><a href="global.html#getAllAnnotations">getAllAnnotations</a></li><li><a href="global.html#getAnnotation">getAnnotation</a></li><li><a href="global.html#getAnnotationCount">getAnnotationCount</a></li><li><a href="global.html#getGeometryByType">getGeometryByType</a></li><li><a href="global.html#indexOf">indexOf</a></li><li><a href="global.html#initialize">initialize</a></li><li><a href="global.html#moveAnnotation">moveAnnotation</a></li><li><a href="global.html#removeAllAnnotations">removeAllAnnotations</a></li><li><a href="global.html#removeAnnotation">removeAnnotation</a></li><li><a href="global.html#removeAnnotationByIndex">removeAnnotationByIndex</a></li><li><a href="global.html#removeAnnotations">removeAnnotations</a></li><li><a href="global.html#requestAuthorization">requestAuthorization</a></li><li><a href="global.html#setResolution">setResolution</a></li><li><a href="global.html#setScale">setScale</a></li><li><a href="global.html#setSize">setSize</a></li><li><a href="global.html#setSystemLibraryPath">setSystemLibraryPath</a></li><li><a href="global.html#toGeometry">toGeometry</a></li><li><a href="global.html#toGeometrys">toGeometrys</a></li><li><a href="global.html#toGraphicsFromGeometry">toGraphicsFromGeometry</a></li><li><a href="global.html#updatePositionbyViewPoint">updatePositionbyViewPoint</a></li></ul>
</nav>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Fri Jan 17 2020 16:23:46 GMT+0800 (GMT+08:00)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
